#include <Logger.h>

namespace AsyncLogger {

	Logger::OutputFunc Logger::func_ = nullptr;
	LogLevel Logger::level_ = static_cast<LogLevel>(0);
	
	Logger::Logger()
	{
	}

	Logger::Logger(const std::string& file, int line, LogLevel level, const char* func)
		:impl_(file, line, level, func)
	{
	}

	Logger::Logger(const std::string& file, int line, LogLevel level)
		: impl_(file, line, level)
	{
	}

	void Logger::setOutput(Logger::OutputFunc func)
	{
		func_ = func;
	}

	void Logger::setLogLevel(LogLevel level)
	{
		level_ = level;
	}

	Logger::~Logger()
	{
		func_(impl_.data(), impl_.len());
	}

	Logger::Impl::Impl()
	{
	}

	Logger::Impl::Impl(const std::string& file, int line, LogLevel level, const char* func)
	{
		std::string logline = file + " " + std::to_string(line) + " " + std::to_string(level) + " " + func + " ";
		stream_ << logline;
	}

	Logger::Impl::Impl(const std::string& file, int line, LogLevel level)
	{
		std::string logline = file + " " + std::to_string(line) + " " + std::to_string(level) + " ";
		stream_ << logline;
	}

	LogStream& Logger::Impl::stream()
	{
		return stream_;
	}

	const char* Logger::Impl::data()
	{
		return stream_.data();
	}

	size_t Logger::Impl::len()
	{
		return stream_.length();
	}
}